package writtenTraining.day34;

import java.util.*;

/**
 * day34:(1)模拟:BC76 [NOIP2008]ISBN号码
 */
public class Main {
    public static void main(String[] args) {
    //    模拟 
        // 输入数据
        Scanner in = new Scanner(System.in);
        char[] chs = in.next().toCharArray();
        int len = chs.length;
        // 判断
        int ret = 0, pos = 0;
        for(int i = 1; i <= 9; ) {
            char ch = chs[pos++]; 
            if(ch >= '0' && ch <= '9') {
                ret += (((int)(ch - '0')) * i);
                i++;  
            } 
        }
        

        char ch = chs[len - 1];
        if(ret % 11 == 10 && ch == 'X') {
            System.out.println("Right");
        }else if(((int)(ch - '0')) == (ret % 11)) {
            System.out.println("Right");
        } else {
            chs[len - 1] =  ret % 11 == 10 ? 
            'X' : (char)(ret % 11 + '0') ;
            String s = "";
            for(int i = 0; i < len; i++) {
                s += chs[i];
            }
            System.out.println(s);
        }
    }
}


/**
 * day34:(2)深度度优先遍历：kotori和迷宫
 */


 class Main2 {
    public static int[] dx = {0,0,-1,1};
    public static int[] dy = {-1,1,0,0};
    public static int row , col;
    public static int exitNum  = 0 ,minRet = 0x3f3f3f3f;
    public static boolean[][] path;
    public static void main(String[] args) {
//        dfs + 深度优先遍历
        // 输入数据
        Scanner in = new Scanner(System.in);
        row = in.nextInt(); col = in.nextInt();
        char[][] chs = new char[row][col];
        for(int i = 0; i < row ; i++) {
            chs[i] = in.next().toCharArray();
        }

        path = new boolean[row][col];
        // 需要入口进行dfs
        for(int i = 0; i < row; i++) {
            for(int j =0; j < col; j++) {
                if(chs[i][j] == 'k') {
                    dfs(chs,i,j,0);

                }
            }
        }

        // 输出结果
        System.out.println(exitNum + " " + (minRet == 0x3f3f3f3f ? - 1 : minRet));
    }

    public static void dfs(char[][]chs, int i, int j , int pos) {
//         统计结果
        if(chs[i][j] == 'e') {
            exitNum++;
            chs[i][j] = '$';
        }
        if(chs[i][j] == '$') {
            minRet = Math.min(minRet,pos);
            return;
        }

        path[i][j] = true;
        for(int k = 0; k < 4; k++) {
            int x = i + dx[k];
            int y = j + dy[k];

//             减枝
            if(x >= 0 && x < row
                    && y >= 0 && y < col
                    && chs[x][y] != '*'
                    && !path[x][y]) {
                dfs(chs,x,y,pos + 1);
//                 回溯
                path[x][y] = false;
            }
        }
    }

}


/**
 * day34:(2)广度度优先遍历：kotori和迷宫
 */



 class Main6 {
    public static int[] dx = {0,0,-1,1};
    public static int[] dy = {-1,1,0,0};
    public static int row , col;
    public static int exitNum  = 0 ,minRet = 0x3f3f3f3f;
    public static boolean[][] path;
    public static void main(String[] args) {
//        广度优先遍历 + bfs
        // 输入数据
        Scanner in = new Scanner(System.in);
        row = in.nextInt(); col = in.nextInt();
        char[][] chs = new char[row][col];
        for(int i = 0; i < row ; i++) {
            chs[i] = in.next().toCharArray();
        }


        int[][] dest = new int[row][col];
        // 需要入口进行bfs
        Queue<int[]> queue = new LinkedList<>();
        for(int i = 0; i < row; i++) {
            for(int j =0; j < col; j++) {
                if(chs[i][j] == 'k') {
                    queue.add(new int[]{i,j});
                } else {
                    dest[i][j] = -1;
                }
            }
        }


        int count = 0, ret = 0x3f3f3f3f;
        while(!queue.isEmpty()) {
            int[] index = queue.poll();
            for(int k = 0; k < 4; k++) {
                int x = index[0] + dx[k];
                int y = index[1] + dy[k];
                if(x >= 0 && x < row
                        && y >= 0 && y < col
                        && dest[x][y] == -1
                        && chs[x][y] != '*') {
                    dest[x][y] = dest[index[0]][index[1]] + 1;
                    if (chs[x][y] != 'e')
                        queue.add(new int[]{x,y});
                }
            }
        }

        for(int i =0; i < row; i++) {
            for(int j = 0; j < col; j++) {
                if(chs[i][j] == 'e' && dest[i][j] != -1) {
                    ret = Math.min(ret,dest[i][j]);
                    exitNum++;
                }
            }
        }

        // 输出结果
        System.out.println( exitNum == 0 ? -1 : exitNum + " " + minRet);

    }


}


/**
 * day34(3)：深度优先遍历 + 记忆化搜索：NC138 矩阵最长递增路径
 */



 class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 递增路径的最大长度
     * @param matrix int整型二维数组 描述矩阵的每个数
     * @return int整型
     */
    int[] dx= {0,0,-1,1};
    int[] dy = {-1,1,0,0};
    boolean[][] path;
    int row , col;
    int[][]memo = new int[1010][1010];
    public int solve (int[][] matrix) {
//        深度优先遍历 + 记忆化搜索

        row = matrix.length; col = matrix[0].length;
        int ret = -0x3f3f3f3f;
        path = new boolean[row][col];
        for(int i =0; i < row ; i++) {
            for(int j = 0; j < col; j++) {
                // 记录走过的值
                path[i][j] = true;
                ret = Math.max(ret,dfs(matrix,i,j) + 1);
                path[i][j] = false;
            }
        }
        return ret;
    }



    public int dfs(int[][] nums , int i , int j ) {
        // 使用备忘录
        if(memo[i][j] != 0) {
            return memo[i][j];
        }

        int len = 0;
        for(int k = 0; k < 4; k++) {
            int x =i + dx[k];
            int y = j + dy[k];
            if (x >= 0 && x < row
                    && y >= 0 && y < col
                    && nums[i][j] < nums[x][y]
                    && !path[x][y]) {
                path[x][y] = true;
                // 接收来自四面八方的最大值
                len = Math.max(dfs(nums,x,y) + 1,len);
                path[x][y] = false;
            }
        }

        // 存入备忘录
        memo[i][j] = len;
        return len;
    }
}
